package io.persimmon.core.dto;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ResponseCode {
    public static final ResponseCode SUCCESS = new ResponseCode("0", "success");
    /**
     * 通用失败
     */
    public static final ResponseCode FAIL = new ResponseCode("1", "fail");
    /**
     * 登陆相关
     */
    public static final ResponseCode TOKEN_NOT_FOUND = new ResponseCode("10_01", "token不存在");
    public static final ResponseCode TOKEN_EXPIRED = new ResponseCode("10_02", "token以过期");
    public static final ResponseCode TOKEN_ERROR = new ResponseCode("10_03", "token以过期");
    /**
     * 参数校验
     */
    public static final ResponseCode PARAM_ILLEGALITY = new ResponseCode("20_01", "参数不合法");
    /**
     * 业务校验
     */
    public static final ResponseCode BUSINESS_NOT_ALLOW = new ResponseCode("20_02", "业务限制");
    /**
     * 网络请求
     */
    public static final ResponseCode NET_TIMEOUT = new ResponseCode("30_01", "网络超时");
    public static final ResponseCode NET_ERROR = new ResponseCode("30_02", "网络调用错误");
    /**
     * 第三方接口
     */
    public static final ResponseCode THIRD_PARTY_ERROR = new ResponseCode("40_01", "第三方接口异常");
    //    public static final List<ResponseCode> responseCodeList = new ArrayList<>();
    public static Map<String, ResponseCode> responseCodeMap = new HashMap<>();
    protected String code;
    protected String msg;

    public ResponseCode() {

    }

    public ResponseCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
//        responseCodeList.add(this);
        responseCodeMap.put(this.code, this);
    }

    public static ResponseCode codeOf(String code) {
        return responseCodeMap.get(code);
    }
}
